package com.lq.ecoldchain.binding.image

import android.arch.lifecycle.MutableLiveData
import android.databinding.BindingAdapter
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions

/*
*2019/1/2 0002  17:43
*function by lq
*/

@BindingAdapter("bind_imageUrl")
fun loadImage(imageView: ImageView, url: String?) {
    Glide.with(imageView.context)
            .load(url)
            .into(imageView)
}

@BindingAdapter("bind_imageUrl_liveData")
fun loadImageData(imageView: ImageView, url: MutableLiveData<String>) {
    if (!url.value.isNullOrEmpty())
        Glide.with(imageView.context).load(url.value).into(imageView)
}


@BindingAdapter("bind_imageUrl_circle")
fun loadImageCircle(imageView: ImageView, url: String?) {
    Glide.with(imageView.context).load(url).apply(RequestOptions.circleCropTransform()).into(imageView)
}